<#include "/@inc/uiMacros.ftl">
<#include "/@inc/funcMacros.ftl">
<#include "/@inc/copyright.txt">
<#assign className = TriaGram + Prefix + LateType + "Dlg">
<#assign intfName = TriaGram + "I" + Prefix + LateType>
<#assign baseName = TriaGram + Prefix + LateType>
<@pp.renameOutputFile name=className+".cpp">
</@pp.renameOutputFile>
//===============================================================================
//
// ${className}.cpp
// The dialog : ${className}
//
//===============================================================================
//  ${Month} ${Year}  Creation: Code generated by the CAA wizard  ${Author}
//===============================================================================
<#-- Doesnt not work :( <#assign x = ${DataTypes(Attributes) }  -->

<@UI_ELEMENTS_DATA_TYPES Attributes  />
// Local Framework
#include "${className}.h"

// Dialog Framework
#include "CATDlgGridConstraints.h"
#include "CATDlgLabel.h"
#include "CATDlgSelectorList.h"
#include "CATMsgCatalog.h"
#include "CATApplicationFrame.h"

//Knowledge Interfaces
#include "CATIParameterEditorFactory.h"
#include "CATIParameterEditor.h"
#include "CATICkeParm.h"

//Local
#include "${intfName}.h"
#include "${TriaGram}IUtlDlgList.h"
#include "${TriaGram}UtlDlgFrame.h"

//------------------------------------------------------------------------------------------

${className}::${className}():
      CATDlgDialog (CATApplicationFrame::GetFrame()->GetMainWindow(),
//CAA2 WIZARD CONSTRUCTOR DECLARATION SECTION
"${className}",CATDlgWndBtnOKCancel|CATDlgGridLayout
//END CAA2 WIZARD CONSTRUCTOR DECLARATION SECTION
                               )
{
//CAA2 WIZARD CONSTRUCTOR INITIALIZATION SECTION
<@ASSIGN_UI_VARS_NULL uiElements />
//END CAA2 WIZARD CONSTRUCTOR INITIALIZATION SECTION
}

//--------------------------------------------------------------------------------------

${className}::~${className}()
{
//  Do not delete the control elements of your dialog:
//     this is done automatically
//  --------------------------------------------------
//CAA2 WIZARD DESTRUCTOR DECLARATION SECTION
<@ASSIGN_UI_VARS_NULL uiElements />
//END CAA2 WIZARD DESTRUCTOR DECLARATION SECTION

}

//--------------------------------------------------------------------------------------
void ${className}::Build(${intfName} * ip${LateType})
{
	CATAssert(NULL != ip${LateType} ) ;
<#list Attributes as attrib>
<#switch attrib.UI>
<#case "Param">
ip${LateType}->Get${attrib.name}(_spParm${attrib.name}) ;
<#break>
</#switch>
</#list>

//CAA2 WIZARD WIDGET CONSTRUCTION SECTION
 SetGridRowResizable(0,1);
<#list uiElements as uiElem>
<#switch uiElem.dlg>
<#case "CATDialog">
_${uiElem.name} = CreateParamFrame( this, "${uiElem.name}", _spParm${uiElem.id}) ;
_${uiElem.name} -> SetGridConstraints(${uiElem.row}, ${uiElem.col}, 1, 1, CATGRID_4SIDES);
<#break>
<#default >
<#assign colSpan = 1>
<#if uiElem.UI == "List"> 	<#assign colSpan = 2> </#if>
<#if uiElem.UI == "BiList"> 	<#assign colSpan = 2> </#if>
<#if uiElem.UI == "PolyList"> <#assign colSpan = 2> </#if>
_${uiElem.name} = new ${uiElem.dlg}(this, "${uiElem.name}", ${uiElem.style} );
_${uiElem.name} -> SetGridConstraints(${uiElem.row}, ${uiElem.col}, ${colSpan}, 1, CATGRID_4SIDES);
<#break>
</#switch>
</#list>
//END CAA2 WIZARD WIDGET CONSTRUCTION SECTION

SetInitialValues(ip${LateType}) ;
}

void ${className}::SetInitialValues(${intfName} * ip${LateType})
{
	CATAssert(NULL != ip${LateType} ) ;

<#list uiElements as uiElem>
<#switch uiElem.dlg>
<#case "CATDlgCombo">
<#list Attributes as attrib>  <#if uiElem.id == attrib.name> <#assign x = attrib> <#break></#if></#list>
<#list x.data  as comboEntry>
_${uiElem.name} -> SetLine("${comboEntry}") ;
</#list>
<#break>
</#switch>
</#list>

<#list Attributes as attrib>
<#if  (attrib.UI?length > 0 ) >
<#list uiElements as uiElem> <#if uiElem.id == attrib.name> <#assign x = uiElem> <#break></#if></#list>
<#switch attrib.type>
<#case "tk_boolean">
	CATBoolean   b${attrib.name} = FALSE  ;
	ip${LateType}->Get${attrib.name}( b${attrib.name} )   ;
	Set${attrib.name}( b${attrib.name} )   ;
<#break>
<#case "tk_integer">
	int   n${attrib.name} = 0  ;
	ip${LateType}->Get${attrib.name}( n${attrib.name} )   ;
	Set${attrib.name}( n${attrib.name} )   ;
<#break>
<#case "tk_double">
	double   d${attrib.name} = 0  ;
	ip${LateType}->Get${attrib.name}( d${attrib.name} )   ;
	Set${attrib.name}( d${attrib.name} )   ;
<#break>
<#case "tk_string">
	CATUnicodeString   str${attrib.name}   ;
	ip${LateType}->Get${attrib.name}( str${attrib.name} )   ;
	Set${attrib.name}( str${attrib.name} )   ;
<#break>
</#switch>
</#if>
</#list>
}

<#-- Return the UI ELements -->
<#list Attributes as attrib>
<#list uiElements as uiElem> <#if uiElem.id == attrib.name> <#assign x = uiElem> <#break></#if></#list>
<#switch attrib.UI>
<#case "">
<#break>
<#case "List">
<#case "BiList">
<#case "PolyList">
${x.dlg} * ${className}::Get${attrib.name}Frame() const
{
	return _${x.name} ;
}
<#break>
<#default >
${x.dlg} * ${className}::Get${x.name}() const
{
	return _${x.name} ;
}
<#break>
</#switch>
</#list>

<#-- Return the values stored in UI ELements -->
<#list Attributes as attrib>
<#if  (attrib.UI?length > 0 ) >
<#list uiElements as uiElem> <#if uiElem.id == attrib.name> <#assign x = uiElem> <#break></#if></#list>
<#switch attrib.type>
<#case "tk_boolean"><#t>
HRESULT ${className}::Get${attrib.name}( CATBoolean   &     ob${attrib.name} )
{
	if(NULL == _${x.name})
	{
		return E_FAIL ;
	}
	// _${x.name} should be CheckButton or Radio Button
	ob${attrib.name}  = ( _${x.name}->GetState() == CATDlgCheck ) ? TRUE : FALSE ;

	return S_OK ;
}

HRESULT ${className}::Set${attrib.name}( CATBoolean   ib${attrib.name} )
{
	if(NULL == _${x.name})
	{
		return E_FAIL ;
	}
	// _${x.name} should be CheckButton or Radio Button
	if( ib${attrib.name}  )
		_${x.name}->SetState(CATDlgCheck )  ;

	return S_OK ;
}

<#break>
<#case "tk_integer"><#t>
HRESULT ${className}::Get${attrib.name}( int   &  on${attrib.name} )
{
	if(NULL == _${x.name})
	{
		return E_FAIL ;
	}

	// _${x.name} should be Combo or Editor/ CheckBox/Radio Button
	<#switch x.dlg >
	<#case "CATDlgCombo" >
	on${attrib.name} = _${x.name}->GetLine(_${x.name}->GetSelect()) ;
	<#break>
	<#case "CATDlgEditor">
	on${attrib.name} =  _${x.name}->GetIntegerValue() ;
	<#break>
	<#default>
	on${attrib.name}  = ( _${x.name}->GetState() == CATDlgCheck ) ? 1 : 0 ;
	</#switch>

	return S_OK ;
}
HRESULT ${className}::Set${attrib.name}( int   in${attrib.name} )
{
	if(NULL == _${x.name})
	{
		return E_FAIL ;
	}

	// _${x.name} should be Combo or Editor/ CheckBox/Radio Button
	<#switch x.dlg >
	<#case "CATDlgCombo" >
	_${x.name}->SetSelect(in${attrib.name}) ;
	<#break>
	<#case "CATDlgEditor">
	 _${x.name}->SetIntegerValue(in${attrib.name} ) ;
	<#break>
	<#default>
	if( in${attrib.name}  )
		_${x.name}->SetState(CATDlgCheck )  ;
	</#switch>

	return S_OK ;
}

<#break>
<#case "tk_double"><#t>
HRESULT ${className}::Get${attrib.name}( double   &     od${attrib.name} )
{
	if(NULL == _${x.name})
	{
		return E_FAIL ;
	}

	// _${x.name} should be Combo or Editor
	<#switch x.dlg >
	<#case "CATDlgCombo" >
	od${attrib.name} = _${x.name}->GetLine(_${x.name}->GetSelect()) ;
	<#break>
	<#case "CATDlgEditor">
	od${attrib.name} =  _${x.name}->GetValue() ;
	<#break>
	</#switch>

	return S_OK ;
}
HRESULT ${className}::Set${attrib.name}( double   id${attrib.name} )
{
	if(NULL == _${x.name})
	{
		return E_FAIL ;
	}

	// _${x.name} should be Combo or Editor
	<#switch x.dlg >
	<#case "CATDlgCombo" >
	_${x.name}->SetSelect(id${attrib.name}) ;
	<#break>
	<#case "CATDlgEditor">
	_${x.name}->SetValue(id${attrib.name} ) ;
	<#break>
	</#switch>

	return S_OK ;
}
<#break>
<#case "tk_string">
HRESULT ${className}::Get${attrib.name}( CATUnicodeString   &  oStr${attrib.name} )
{
	if(NULL == _${x.name})
	{
		return E_FAIL ;
	}

	// _${x.name} should be Combo or Editor
	<#switch x.dlg >
	<#case "CATDlgCombo" >
	_${x.name}->GetLine(oStr${attrib.name}, _${x.name}->GetSelect()) ;
	<#break>
	<#case "CATDlgEditor">
	oStr${attrib.name} =  _${x.name}->GetText() ;
	<#break>
	</#switch>

	return S_OK ;
}
HRESULT ${className}::Set${attrib.name}( const CATUnicodeString   &  iStr${attrib.name} )
{
	if(NULL == _${x.name})
	{
		return E_FAIL ;
	}

	// _${x.name} should be Combo or Editor
	<#switch x.dlg >
	<#case "CATDlgCombo" >
	_${x.name}->SetSelect(iStr${attrib.name}) ;
	<#break>
	<#case "CATDlgEditor">
	_${x.name}->SetText(iStr${attrib.name} ) ;
	<#break>
	</#switch>

	return S_OK ;
}
</#switch></#if></#list>

//-------------------------------------------------------------------------
// ${className} : CreateParamFrame
//-------------------------------------------------------------------------
CATDlgFrame * ${className}::CreateParamFrame(const CATDialog *iParent,
													  const CATString &iName,
													  const CATICkeParm_var &ispParam)
{
	if (NULL_var == ispParam)
		return NULL ;

    CATDlgFrame *pFrame = NULL ;
	CATIParameterEditor * pEditor = NULL;

    // Set your actual parameter here
    CATApplicationFrame * frame = CATApplicationFrame::GetFrame ();
    if(NULL == frame)
        return NULL ;

    CATIParameterEditorFactory * pFactory = NULL;
    HRESULT hr = frame -> QueryInterface (CATIParameterEditorFactory::ClassId(), (void **) &pFactory);
    if (SUCCEEDED (hr) && pFactory)
    {
       hr = pFactory -> CreateParameterEditor (iParent, iName, 1, pEditor );
       if (SUCCEEDED(hr)&& pEditor )
       {
          pEditor  -> SetEditedParameter (ispParam);
          pFrame = pEditor  -> GetFrame();
          if(pFrame)
          {
			  pFrame->SetPowerInputLink(1) ;
          }
          pEditor  -> Release();
       }
       pFactory -> Release();
    }

    return pFrame ;
}

